import org.junit.Test;

import java.util.function.BooleanSupplier;

public class SupermarketShopping {
    //测试顾客股买商品
    @Test
    public void testShopping(){
        ShoppingCart customerA = new ShoppingCart();
        // 假设顾客A购买3斤苹果，2斤草莓
        customerA.setWeight(0, 3);
        customerA.setWeight(1, 2);

        double totalPriceA = customerA.calculateTotalPrice();
        System.out.println("顾客A购买商品的总价为：" + totalPriceA + "元");

        ShoppingCart customerB = new ShoppingCart();
        // 假设顾客B购买2斤苹果，1斤草莓，1斤芒果
        customerB.setWeight(0, 2);
        customerB.setWeight(1, 1);
        customerB.setWeight(2, 1);

        double totalPriceB = customerB.calculateTotalPrice();
        System.out.println("顾客B购买商品的总价为：" + totalPriceB + "元");

        ShoppingCart customerC = new ShoppingCart();
        // 假设顾客C购买1斤苹果，3斤草莓，2斤芒果
        customerC.setWeight(0, 1);
        customerC.setWeight(1, 3);
        customerC.setWeight(2, 2);

        double totalPriceC = customerC.calculateTotalPriceWithStrawberryDiscount();
        System.out.println("顾客C购买商品的总价为：" + totalPriceC + "元");

        ShoppingCart customerD = new ShoppingCart();
        // 假设顾客D购买4斤苹果，2斤草莓，3斤芒果
        customerD.setWeight(0, 4);
        customerD.setWeight(1, 2);
        customerD.setWeight(2, 3);

        double totalPriceD = customerD.calculateTotalPriceWithFullReduction();
        System.out.println("顾客D购买商品的总价为：" + totalPriceD + "元");

        //验证计算结果的正确性

        BooleanSupplier validateA = () -> totalPriceA == (3 * 8 + 2 * 13);
        System.out.println("顾客A总价计算结果是否正确：" + validateA.getAsBoolean());


        BooleanSupplier validateB = () -> totalPriceB == (2 * 8 + 1 * 13 + 1 * 20);
        System.out.println("顾客B总价计算结果是否正确：" + validateB.getAsBoolean());


        BooleanSupplier validateC = () -> totalPriceC == (1 * 8 + 3 * 13 * 0.8 + 2 * 20);
        System.out.println("顾客C总价计算结果是否正确：" + validateC.getAsBoolean());

        BooleanSupplier validateD = () -> totalPriceD == ((4 * 8 + 2 * 13 * 0.8 + 3 * 20) - 10);
        System.out.println("顾客D总价计算结果是否正确：" + validateD.getAsBoolean());
    }



}
